#include "BlockQueue.hpp"

void* Consumer(void* args)
{
    BlockQueue<int>* bq = static_cast<BlockQueue<int>*>(args);
    while(true) {
        int data = bq->pop();
        printf("消费者消费了一个数据:%d\n", data);
        sleep(2);
    }
    
}

void* Producer(void* args)
{
    BlockQueue<int>* bq = static_cast<BlockQueue<int>*>(args);
    int data = 0;
    while(true) {
        data++;
        bq->push(data);
        printf("生产者生产了一个数据:%d\n", data);
    }
}

int main()
{
    BlockQueue<int>* bq = new BlockQueue<int>();
    pthread_t c, p;
    pthread_create(&c, nullptr, Consumer, bq);
    pthread_create(&p, nullptr, Producer, bq);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);
    delete bq;
    return 0;
}